package com.feng.show.service.impl;

import com.feng.show.comm.ServerResponse;
import com.feng.show.dao.ProductAreaMapper;
import com.feng.show.entity.ProductArea;
import com.feng.show.service.IProductAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("IProductAreaService")
public  class ProductAreaImpl implements IProductAreaService {
/*
地区列表
 */
    @Autowired
    private ProductAreaMapper mapper;

    @Override
    public ServerResponse<String> addProductArea(String name, String des) {
        return null;
    }

    @Override
    public ServerResponse<String> addProductArea(String name, String des, String userId) {
        ProductArea item=new ProductArea();
        item.setAreaDes(des);
        item.setAreaName(name);
        int count=mapper.insert(item);
        if(count>0){
          return   ServerResponse.createBySuccessMsg("增加成功");
        }else{
            return  ServerResponse.createByErrorMsg("添加失败");
        }
    }

    @Override
    public ServerResponse<List<ProductArea>> getAreaList(String userId) {
        List<ProductArea> list;

        try{
             list=mapper.selectByExample(null);
        }catch(Exception e){
            return ServerResponse.createBySuccessMsg("异常");
        }

        if(list==null){
            return ServerResponse.createBySuccessMsg("没有数据，请添加");
        }
        return ServerResponse.createBySuccesMsg(list);
    }

//
//    @Override
//    public ServerResponse<String> addProductType(String name,  String des) {
//
//
//        long count=serarchByName(name);
//        if(count>0){
//            return  ServerResponse.createBySuccessMsg(name+"已存在，不能重复添加");
//        }
//
//
//        ProductType type=new ProductType();
//        type.setDes(des);
//        type.setName(name);
//        type.setNo(no);
//
//        int status=mapper.insert(type);
//        if(status!=0){
//            return ServerResponse.createBySuccessMsg("增加成功");
//        }else{
//            return ServerResponse.createBySuccessMsg("添加失败");
//        }
//
//    }
//
//    @Override
//    public Long serarchByName(String name) {
//        ProductTypeExample typeExample=new ProductTypeExample();
//        ProductTypeExample.Criteria criteria=typeExample.createCriteria() ;
//        criteria.andNameEqualTo(name);
//
//        long count=mapper.countByExample(typeExample);
//        return count;
//
//    }
//
//    @Override
//    public ServerResponse<List<ProductType>> getProductTypeList(String userId) {
//
//        List<ProductType>  list=mapper.selectByExample(null);
//        return ServerResponse.createBySuccesMsg(list);
//    }
}
